package models

import (
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/primitive"
)

type Group struct {
	Id        primitive.ObjectID   `json:"id" bson:"_id"`
	GroupName string               `json:"groupName" bson:"groupName"`
	MembersId []primitive.ObjectID `json:"membersId" bson:"membersId"`
	HeadUrl   string               `json:"headUrl" bson:"headUrl"`
}

func NewGroup(groupName string, membersId []primitive.ObjectID, headUrl string) *Group {
	return &Group{
		GroupName: groupName,
		MembersId: membersId,
		HeadUrl:   headUrl,
	}
}

func (group *Group) ToBson() *bson.D {
	data := bson.D{}
	if group.GroupName != "" {
		data = append(data, bson.E{Key: "groupName", Value: group.GroupName})
	}
	if group.MembersId != nil {
		data = append(data, bson.E{Key: "membersId", Value: group.MembersId})
	}
	if group.HeadUrl != "" {
		data = append(data, bson.E{Key: "headUrl", Value: group.HeadUrl})
	}

	return &data
}
